const Router = require('koa-router')

const userRouter = new Router({ prefix: '/user' })

const { verifyAuth } = require('../middlewares/auth.middleware')

const {
	wxLogin,
	testHome,
	getUserInfo,
	getCartList,
	addToCart,
	modifyCartGoodsNum,
	removeCartGoods,
	removeAllCartGoods,
	getAddressList,
	createAddress,
	updateAddress,
	removeAddress,
	generateOrder,
	updateOrderPayState,
	getOrderList
} = require('../controllers/user.controller')

// 登录授权
userRouter.post('/wexin-login', wxLogin)

// 测试登录鉴权接口
userRouter.all('/home', verifyAuth, testHome)

// 获取用户信息
userRouter.get('/my', verifyAuth, getUserInfo)

// 添加到购物车
userRouter.post('/my/carts', verifyAuth, addToCart)

// 获取购物车列表
userRouter.get('/my/carts', verifyAuth, getCartList)

// 更改购物车商品数量
userRouter.put('/my/carts/:cartId', verifyAuth, modifyCartGoodsNum)

// 删除某个购物车商品
userRouter.delete('/my/carts/:cartId', verifyAuth, removeCartGoods)

// 删除所有购物车商品
userRouter.delete('/my/carts', verifyAuth, removeAllCartGoods)

// 获取用户地址列表
userRouter.get('/my/address', verifyAuth, getAddressList)

// 创建用户地址
userRouter.post('/my/address', verifyAuth, createAddress)

// 修改用户地址
userRouter.put('/my/address/:addressId', verifyAuth, updateAddress)

// 删除用户地址
userRouter.delete('/my/address/:addressId', verifyAuth, removeAddress)

// 生成用户订单
userRouter.post('/my/order', verifyAuth, generateOrder)

// 更新订单支付状态
userRouter.put('/my/order', verifyAuth, updateOrderPayState)

// 获取订单列表
userRouter.get('/my/order', verifyAuth, getOrderList)


module.exports = userRouter
